package br.com.ximp.addessi.client.ui;

import java.util.List;

import br.com.ximp.addessi.shared.entity.Conta;
import br.com.ximp.addessi.shared.service.ContaSvc;
import br.com.ximp.addessi.shared.service.ContaSvcAsync;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class TransacoesUI extends Composite{
	interface MyUiBinder extends UiBinder<Widget, TransacoesUI> {}
	private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);
	
	@UiField VerticalPanel pnlContas;
	
	public TransacoesUI() {
		initWidget(uiBinder.createAndBindUi(this));
		ContaSvcAsync contaSvc = (ContaSvcAsync) GWT.create(ContaSvc.class);
		contaSvc.findTodas(new AsyncCallback<List<Conta>>() {
			
			@Override
			public void onSuccess(List<Conta> result) {
				if (result == null) return;
				for (Conta conta : result) {
					ContaUI contaUI = new ContaUI();
					contaUI.setConta(conta);
					pnlContas.add(contaUI);
				}				
			}
			
			@Override
			public void onFailure(Throwable caught) {
				GWT.log(caught.getMessage(), caught);				
			}
		});
	}
}
